package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	@Operation(summary = "获取分类数据")
	@GetMapping("/getBaseCategoryList")
	public Result getBaseCategoryList(){
		// 调用service层方法 JSONObject相当于map
		List<JSONObject> list=baseCategoryService.getBaseCategoryList();
		return Result.ok(list);
	}
	@Operation(summary = "根据一级分类id查询属性标签数据")
	@GetMapping("/findAttribute/{category1Id}")
	public Result findAttribute(@PathVariable Long category1Id){
		List<BaseAttribute> list=baseCategoryService.findAttribute(category1Id);
		return Result.ok(list);
	}

	/**
	 * 根据三级分类id查询分类数据
	 * @param category3Id
	 * @return
	 */
	@Operation(summary = "根据三级分类id查询分类数据")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result getCategoryView(@PathVariable Long category3Id){
		//调用服务层方法
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
		//返回数据
		return Result.ok(baseCategoryView);
	}

	/**
	 * 根据一级分类id查询数据
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类id查询数据")
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public Result getBaseCategoryList(@PathVariable Long category1Id){
		//调用服务层方法
		JSONObject jsonObjects=baseCategoryService.getBaseCategoryList(category1Id);
		//返回数据
		return Result.ok(jsonObjects);
	}

	/**
	 * 根据一级分类id查询三级分类数据
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类id查询三级分类数据")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){
		//调用服务层方法
		List<BaseCategory3> list =baseCategoryService.findTopBaseCategory3(category1Id);
		//返回数据
		return Result.ok(list);
	}

	/**
	 * 查询一级分类信息
	 * @return
	 */
	@Operation(summary = "查询一级分类信息")
	@GetMapping("findAllCategory1")
	public Result findAllCategory1(){
		//调用服务层方法
		//List<BaseCategory1> list = baseCategoryService.findAllCategory1();
		//返回数据
		return Result.ok(baseCategoryService.list());
	}
}

